package IOTest;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Input {
    public static void main(String[] args) {
        try (InputStream inputStream = new FileInputStream("d:/example/test.txt")){
            while (true) {
                byte[] bytes = new byte[1024];
                int n = inputStream.read(bytes);
                if (n == -1) {
                    break;
                }
                for (int i = 0; i < n; i++) {
                    System.out.printf("%x ",bytes[i]);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void test1() {
        InputStream inputStream = null;
        try{
            inputStream = new FileInputStream("d:/example/test.txt");
            while (true) {
                byte[] bytes = new byte[1024];
                int n = inputStream.read(bytes);
                if (n == -1) {
                    break;
                }
                for (int i = 0; i < n; i++) {
                    System.out.printf("%x ",bytes[i]);
                }
            }
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            if(inputStream != null){
                try {
                    inputStream.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
